﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;
namespace project
{
    public partial class EditStudent : UIForm
    {
        private string old_id, old_pwd, old_name, old_dept, old_phone;
private void uiButton1_Click(object sender, EventArgs e)
        {
            // 确定
            string id = uiTextBox1.Text;
            string pwd = uiTextBox2.Text;
            string name = uiTextBox3.Text;
            string dept = uiTextBox4.Text;
            string phone = uiTextBox5.Text;
            string sqlstr = $"update student set " +
                $"number='{id}',"+
                $"pwd='{pwd}',"+
                $"name='{name}',"+
                $"dept='{dept}',"+
                $"phone_number='{phone}'"+
                $"where number='{old_id}'; ";


            if (string.IsNullOrEmpty(id) ||
                string.IsNullOrEmpty(pwd)||
                string.IsNullOrEmpty(name)||
                string.IsNullOrEmpty(dept)||
                string.IsNullOrEmpty(phone))
            {
                MessageBox.Show("存在空数据，请检查后再修改", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int reslut = SqlHelper.ExecuteNonQuery(sqlstr);
            if (reslut == 1)
            {

                MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                ClearTextBox();
            }
            else
            {
                MessageBox.Show("修改失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        
        }

        private void uiButton2_Click(object sender, EventArgs e)
        {
            // 取消
            this.Close();
        }

        private void uiLabel1_Click(object sender, EventArgs e)
        {

        }

        public EditStudent()
        {
            InitializeComponent();
        }
        public EditStudent(string  id, string pwd, string name, string dept, string phone)
        {
            InitializeComponent();
            old_id = id;
            old_pwd = pwd;
            old_name = name;
            old_dept = dept;
            old_phone = phone;
            uiTextBox1.Text = id;
            uiTextBox2.Text = pwd;
            uiTextBox3.Text = name;
            uiTextBox4.Text = dept;
            uiTextBox5.Text = phone;
        }
        private void ClearTextBox()
        {

            uiTextBox1.Text = null;
            uiTextBox2.Text = null;
            uiTextBox3.Text = null;
            uiTextBox4.Text = null;
            uiTextBox5.Text = null;
        }
    }
}
